package com.scs.application.modules.upms.security;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.scs.application.core.exceptions.BusinessException;
import com.scs.application.modules.base.entity.Hospital;
import com.scs.application.modules.base.entity.Supplier;
import com.scs.application.modules.upms.vo.UserVO;
import lombok.Data;

@Data
public class UserPrincipal extends UserVO {
    /**
     * 供应商ID
     */
    private Supplier supplier;

    /**
     * 医院ID
     */
    private Hospital hospital;
    private String versionApi;

    @JsonIgnore
    @JSONField(serialize = false, deserialize = false)
    public boolean isSupplier() {
        return supplier != null;
    }

    @JsonIgnore
    @JSONField(serialize = false, deserialize = false)
    public boolean isHospital() {
        return hospital != null;
    }


    @JsonIgnore
    @JSONField(serialize = false, deserialize = false)
    public String getSupplierId() {
        if (!isSupplier()) {
            throw new BusinessException("当前用户非供应商身份，不允许操作");
        }
        return supplier.getId();
    }

    @JsonIgnore
    @JSONField(serialize = false, deserialize = false)
    public String getHospitalId() {
        if (!isHospital()) {
            throw new BusinessException("当前用户非医院身份，不允许操作");
        }
        return hospital.getId();
    }

    public Hospital getHospitalNoValid() {
        return hospital;
    }
}
